package com.aoxin.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.system.SlfAttachmentMapper;
import com.aoxin.model.system.SlfAttachment;
import com.aoxin.service.inter.system.AttachmentService;
import com.aoxin.util.ErrorUtil;

@Service("attachmentService")
public class AttachmentServiceImpl implements AttachmentService {

	@Autowired
	private SlfAttachmentMapper slfAttachmentMapper;

	@Override
	@Transactional
	public SlfAttachment insertAttachment(SlfAttachment attachment) {
		Assert.notNull(attachment, String.format(ErrorUtil.PARAMETER_NULL, "attachment"));
		this.slfAttachmentMapper.insertSelective(attachment);
		return attachment;
	}

	@Override
	@Transactional
	public void deleteAttachments(List<Integer> attachmentIds) {
		Assert.notEmpty(attachmentIds, String.format(ErrorUtil.PARAMETER_NULL, "attachmentIds"));
		this.slfAttachmentMapper.deleteByPrimaryKey(attachmentIds);
	}

	@Override
	@Transactional
	public void updateAttachment(SlfAttachment attachment) {
		Assert.notNull(attachment, String.format(ErrorUtil.PARAMETER_NULL, "attachment"));
		this.slfAttachmentMapper.updateByPrimaryKeySelective(attachment);
	}

	@Override
	public SlfAttachment getAttachment(Integer attachmentId) {
		Assert.notNull(attachmentId, String.format(ErrorUtil.PARAMETER_NULL, "attachmentIds"));
		return this.slfAttachmentMapper.selectByPrimaryKey(attachmentId);
	}

	@Override
	public List<SlfAttachment> getByBizIdAndBizType(Integer bizId, Integer bizType) {
		Assert.notNull(bizId, String.format(ErrorUtil.PARAMETER_NULL, "bizId"));
		Assert.notNull(bizType, String.format(ErrorUtil.PARAMETER_NULL, "bizType"));
		return this.slfAttachmentMapper.getByBizIdAndBizType(bizId, bizType);
	}

}
